// RealtimeContext.js
import React, { createContext, useContext, useState, useCallback } from 'react';

const RealtimeContext = createContext(); // 定义上下文

export const RealtimeProvider = ({ children }) => {
  const [checkedStates, setCheckedStates] = useState({}); // 存储每个卫星系统的选中状态

  const updateCheckedList = useCallback((satelliteType, checkedList) => {
    // 添加调试打印语句
    console.log('更新选中列表:', satelliteType, checkedList);
    setCheckedStates(prev => ({
      ...prev,
      [satelliteType]: checkedList
    }));
  }, []);

  return (
    <RealtimeContext.Provider value={{ checkedStates, updateCheckedList }}>
      {children}
    </RealtimeContext.Provider>
  );
};

export const useRealtimeContext = () => useContext(RealtimeContext); // 自定义hook，用于获取上下文